/**
 * Created by George Chan on 2015/6/24.
 * 瀑布机器人
 */
'use strict';
var async_request = require('request');
var C = require('../config');

//pubuIM
function pubuIM(msginfo) {
    this.set(msginfo);

}

pubuIM.prototype.set = function (msgInfo) {
    this.text = msgInfo['text'] || "";//文本
    this.title = msgInfo['title'] || "";//标题
    this.description = msgInfo['description'] || "";//描述
    this.url = msgInfo['url'] || "";//链接
    this.color = msgInfo['color'] || "warning";//color: "warning|info|primary|error|muted|success
    this.name = msgInfo['name'] || C.pubuIM.displayUser.name;//机器人名称
    this.avatarUrl = msgInfo['avatarUrl'] || C.pubuIM.displayUser.avatarUrl;//头像地址


};

//发送通知
pubuIM.prototype.send = function () {
    var tempAtt = {};
    tempAtt.title = this.title;
    tempAtt.description = this.description;
    tempAtt.url = this.url;
    tempAtt.color = this.color;
    let tempSend = {};
    tempSend.text = this.text;
    tempSend.attachments = [];
    tempSend.attachments[0] = tempAtt;
    tempSend.displayUser = {};
    tempSend.displayUser.name = this.name;
    tempSend.displayUser.avatarUrl = this.avatarUrl;
    async_request.post({url: C.pubuIM.url, form: tempSend}, function (e, r, body) {
        if (e) {
            console.error(e);
        }
    })

};

//exports.pubuIM = pubuIM;
module.exports = pubuIM;